package com.example.spring.ioc.apiConfig;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.support.GenericApplicationContext;

/**
 * Project:spring
 * <p>
 * Title:ApiConfigExample.java
 * <p>
 * Description:
 * <p>
 * Copyrigth:Jiang Software LTD.co Copyright (c) 2022
 * <p>
 * 
 * @version 1.0
 * @since 1.8
 * @author jiang
 * @history 2022 jiang create
 */
public class ApiConfigExample {

	public static void main(String[] args) {
		 //创建注解相关的上下文
		GenericApplicationContext context=new GenericApplicationContext();
	    //创建GenericBeanDefinition			
        GenericBeanDefinition beanDefinition=new GenericBeanDefinition();
        //设置BeanClass
        beanDefinition.setBeanClass(Car.class);
        //设置属性
        MutablePropertyValues propertyValues=new MutablePropertyValues();
        propertyValues.addPropertyValue("brand","大众");
        propertyValues.addPropertyValue("color","red");
        propertyValues.addPropertyValue("speed",100);
        beanDefinition.setPropertyValues(propertyValues);
        
        beanDefinition.setInitMethodName("init1");
        beanDefinition.setInitMethodName("init2");
        beanDefinition.setDestroyMethodName("destroy1");
        beanDefinition.setDestroyMethodName("destroy2");
		//注册BeanDefinition
        context.registerBeanDefinition("car",beanDefinition);
		//刷新IoC容器
        context.refresh();
		//获取Bean
        Car car = context.getBean("car", Car.class);
        System.out.println(car);
		//关闭上下文
        context.close();

	}

}
